package main

import (
	"github.com/hajimehoshi/ebiten/v2"
	"image"
)

type Bullet struct {
	Image  *ebiten.Image
	Width  int
	Height int
	X      float64
	Y      float64
	Speed  float64
}

func NewBullect(cfg *Config, ship *Ship) (*Bullet, error) {
	//fmt.Println(cfg.BulletWidth, cfg.BulletHeight, "    ", 1111111)
	rect := image.Rect(0, 0, cfg.BulletWidth, cfg.BulletHeight)
	img := ebiten.NewImageWithOptions(rect, nil)
	img.Fill(cfg.BulletColor)
	return &Bullet{
		Image:  img,
		Width:  cfg.BulletWidth,
		Height: cfg.BulletHeight,
		X:      ship.X + float64(ship.Width-cfg.BulletWidth)/2,
		Y:      ship.Y - float64(cfg.BulletHeight),
		Speed:  cfg.BulletSpeed,
	}, nil
}

func (bullet *Bullet) Draw(screen *ebiten.Image) {
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(bullet.X, bullet.Y)
	screen.DrawImage(bullet.Image, op)
}
